# pyinstaller -F -i main.ico main.py -n 公制英制转换V1.00

grade64 = [
    ('0', 0, '0'),
    ('1/64', 0.015625, '1/64'),
    ('1/32', 0.03125, '2/64'),
    ('3/64', 0.046875, '3/64'),
    ('1/16', 0.0625, '4/64'),
    ('5/64', 0.078125, '5/64'),
    ('3/32', 0.09375, '6/64'),
    ('7/64', 0.109375, '7/64'),
    ('1/8', 0.125, '8/64'),
    ('9/64', 0.140625, '9/64'),
    ('5/32', 0.15625, '10/64'),
    ('11/64', 0.171875, '11/64'),
    ('3/16', 0.1875, '12/64'),
    ('13/64', 0.203125, '13/64'),
    ('7/32', 0.21875, '14/64'),
    ('15/64', 0.234375, '15/64'),
    ('1/4', 0.25, '16/64'),
    ('17/64', 0.265625, '17/64'),
    ('9/32', 0.28125, '18/64'),
    ('19/64', 0.296875, '19/64'),
    ('5/16', 0.3125, '20/64'),
    ('21/64', 0.328125, '21/64'),
    ('11/32', 0.34375, '22/64'),
    ('23/64', 0.359375, '23/64'),
    ('3/8', 0.375, '24/64'),
    ('25/64', 0.390625, '25/64'),
    ('13/32', 0.40625, '26/64'),
    ('27/64', 0.421875, '27/64'),
    ('7/16', 0.4375, '28/64'),
    ('29/64', 0.453125, '29/64'),
    ('15/32', 0.46875, '30/64'),
    ('31/64', 0.484375, '31/64'),
    ('1/2', 0.5, '32/64'),
    ('33/64', 0.515625, '33/64'),
    ('17/32', 0.53125, '34/64'),
    ('35/64', 0.546875, '35/64'),
    ('9/16', 0.5625, '36/64'),
    ('37/64', 0.578125, '37/64'),
    ('19/32', 0.59375, '38/64'),
    ('39/64', 0.609375, '39/64'),
    ('5/8', 0.625, '40/64'),
    ('41/64', 0.640625, '41/64'),
    ('21/32', 0.65625, '42/64'),
    ('43/64', 0.671875, '43/64'),
    ('11/16', 0.6875, '44/64'),
    ('45/64', 0.703125, '45/64'),
    ('23/32', 0.71875, '46/64'),
    ('47/64', 0.734375, '47/64'),
    ('3/4', 0.75, '48/64'),
    ('49/64', 0.765625, '49/64'),
    ('25/32', 0.78125, '50/64'),
    ('51/64', 0.765625, '51/64'),
    ('13/16', 0.8125, '52/64'),
    ('53/64', 0.828125, '53/64'),
    ('27/32', 0.84375, '54/64'),
    ('55/64', 0.859375, '55/64'),
    ('7/8', 0.875, '56/64'),
    ('57/64', 0.890625, '57/64'),
    ('29/32', 0.90625, '58/64'),
    ('59/64', 0.921875, '59/64'),
    ('15/16', 0.9375, '60/64'),
    ('61/64', 0.953125, '61/64'),
    ('31/32', 0.96875, '62/64'),
    ('63/64', 0.984375, '63/64'),
    ('1', 1, '1'),

]


def Calculate_mmToinch(num_mm):
    num_inch = num_mm / 25.4  # 计算英制
    num_inch_int = int(num_inch)  # 取英制的整数部分
    # print(num_inch_int)
    num_inch_decimals = num_inch - num_inch_int  # 取英制的小数部分
    # print(num_inch_decimals)
    num_inch_grade = Calculate_grade(num_inch_decimals)  # 取英制的分母部分

    if num_inch_grade[1]==0:
        print("\n英寸：\n" + str(num_inch_int) + '"')
        if (num_inch_int/12)>1:
            print("\n英尺：\n" + str(int(num_inch_int / 12)) + "'" + str(num_inch_int % 12) + '"')


    elif num_inch_grade[1]==1:
        num_inch_int = num_inch_int + 1
        print("\n英寸：\n" + str(num_inch_int) + '"')
        if (num_inch_int/12)>1:
            print("\n英尺：\n" + str(int(num_inch_int / 12)) + "'" + str(num_inch_int % 12) + '"')

    else:
        print("\n英寸(小数形式)：\n" + str(num_inch))
        # print("英寸(64分母)：" + str(num_inch_int) + " " + str(num_inch_grade[2]) + '"')
        print("\n英寸(分数形式)：\n" + str(num_inch_int) + " " + str(num_inch_grade[0]) + '"')
        if (num_inch_int/12)>1:
            print("\n英尺(分数形式)：\n" + str(int(num_inch_int / 12)) + "'" + str(num_inch_int % 12) + " " + str(num_inch_grade[0]) + '"')


# 计算最接近的分数
def Calculate_grade(num_inch_decimals):
    result_num = 2
    result_tub = ()

    for num in grade64:
        num1 = abs(num[1] - num_inch_decimals)
        if result_num > num1:
            result_num = num1
            result_tub = num

    # print(result_num)
    # print(result_tub)

    return result_tub


if __name__ == '__main__':
    while True:
        num_mm = float(input("毫米："))
        # num_mm = 500
        Calculate_mmToinch(num_mm)
        # Calculate_grade(0.6850393700787407)
        print("")
        print("="*30)
        print("")

